package com.xiang.consumer;

import com.xiang.config.FanoutConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 广播队列消费者
 *
 * @author: xiangtianlei
 * @Date: 2022-9-10
 */
@Component
public class Fanout {

    Logger log = LoggerFactory.getLogger(Fanout.class);

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(FanoutConfig.FANOUR_QUEUE_ONE),
            exchange = @Exchange(value = FanoutConfig.FANOUT_EXCHANGE, type = ExchangeTypes.FANOUT)
    ))
    public void listenerFanoutQueueOne(String msg) {
        log.info("消费者One监听队列：" + FanoutConfig.FANOUR_QUEUE_ONE + "的消息：" + msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(FanoutConfig.FANOUR_QUEUE_TWO),
            exchange = @Exchange(name = FanoutConfig.FANOUT_EXCHANGE, type = ExchangeTypes.FANOUT)
    ))
    public void listenerFanoutQueueTwo(String msg) {
        log.info("消费者Two监听队列：" + FanoutConfig.FANOUR_QUEUE_TWO + "的消息：" + msg);
    }
}
